<HTML><HEAD><TITLE>term_hash(?Term, +Depth, +Range, -Hash)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Comparing and Sorting</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>term_hash(?Term, +Depth, +Range, -Hash)</H1>
Computes a hash value for an arbitrary term
<DL>
<DT><EM>Term</EM></DT>
<DD>An arbitrary term
</DD>
<DT><EM>Depth</EM></DT>
<DD>An integer
</DD>
<DT><EM>Range</EM></DT>
<DD>An integer
</DD>
<DT><EM>Hash</EM></DT>
<DD>A variable or an integer
</DD>
</DL>
<H2>Description</H2>
    This predicate attempts to computes a hash value for an arbitrary term.
    The computed hash value lies between 0 and Range-1.
<P>
    The Depth argument specifies the nesting depth of the term up to
    which the term's components are taken into account for the
    computation of the hash value.  More deeply nested parts of the
    term will be ignored.  If the term contains uninstantiated parts in
    the portion up to Depth, no reliable hash value can be computed
    and the predicate succeeds, leaving Hash uninstantiated.  If Depth
    is set to -1, the whole depth of the term will be used for computing
    the hash value.  If Depth is set to 0, the hash value will be 0.
    The main functor of a term is taken to be at depth 1, its arguments
    at depth 2 etc.

<H3>Modes and Determinism</H3><UL>
<LI>term_hash(?, +, +, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Depth or Range are not instantiated
<DT><EM>(5) type error </EM>
<DD>Depth or Range are not integers
</DL>
<H2>Examples</H2>
<PRE>
Success:
    [eclipse 1]: term_hash(hello, 1, 100, H).
    H = 4
    yes.

    [eclipse 2]: term_hash(world, 1, 100, H).
    H = 84
    yes.

    [eclipse 15]: term_hash(foo(bar,3,4.5), -1, 100, H).
    H = 40
    yes.

    [eclipse 15]: term_hash(foo(bar,3,4.5), 1, 100, H).
    H = 72
    yes.

    [eclipse 18]: term_hash(foo(X,3,4.5), 1, 100, H).
    X = X
    H = 72
    yes.

    [eclipse 19]: term_hash(foo(X,3,4.5), 2, 100, H).
    X = X
    H = H
    yes.
</PRE>
<H2>See Also</H2>
<A HREF="../../lib/hash/hash_create-1.html">hash : hash_create / 1</A>, <A HREF="../../kernel/termmanip/dim-2.html">dim / 2</A>
</BODY></HTML>
